# !/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project ：project
# @FileName：config.py
# @IDE     ：PyCharm
# @Author  ：叶鸟翼
# @Time    ：2022/10/6 11:15
import configparser

from settings import CONFIG_PATH


class ReadConfig:
    """读取config.ini"""

    def __init__(self):
        self.conf = configparser.ConfigParser()
        self.conf.read(CONFIG_PATH, encoding="utf-8")

    def get_host(self):
        return self.conf.get('http', 'host')

    def get_log_config(self):
        return {
            'log_cli': self.conf.getboolean('log', 'log_cli'),
            'log_cli_level': self.conf.get('log', 'log_cli_level'),
            'log_cli_date_format': self.conf.get('log', 'log_cli_date_format', raw=True),
            'log_cli_format': self.conf.get('log', 'log_cli_format', raw=True),
            'log_file_level': self.conf.get('log', 'log_file_level'),
            'log_file_date_format': self.conf.get('log', 'log_file_date_format', raw=True),
            'log_file_format': self.conf.get('log', 'log_file_format', raw=True),
            'log_level': self.conf.get('log', 'log_level')
        }

    def get_mail_config(self):
        return {
            'user': self.conf.get('mail', 'user'),
            'to_addrs': self.conf.get('mail', 'receiver').split(', '),
            'password': self.conf.get('mail', 'password'),
            'host': self.conf.get('mail', 'host'),
            'port': self.conf.getint('mail', 'port'),
            'is_file': True
        }

    def get_dingtalk_config(self):
        return {
            'url': self.conf.get('dingtalk', 'url'),
            'secret': self.conf.get('dingtalk', 'secret'),
            'isatall': self.conf.getboolean('dingtalk', 'isatall'),
            'except_info': self.conf.getboolean('dingtalk', 'except_info')
        }


rfc = ReadConfig()
